
function(def_application app_name linker_file)
    message(STATUS "add executable: ${app_name}")
    add_executable(${app_name})
    target_sources(${app_name} PRIVATE 
        ../common/startup.s
        ../common/misc.c
        ../common/uart.c
        ../common/board.c
        ../common/extern_sram.c
    )
    target_link_libraries(${app_name} stm32f4xx_hal)
    target_include_directories(${app_name} PRIVATE
        .
        ../common
    )
    target_link_options(${app_name} PRIVATE
        -T${CMAKE_CURRENT_SOURCE_DIR}/../common/${linker_file}
        -Wl,-Map=${CMAKE_CURRENT_BINARY_DIR}/${app_name}.map
    )

    add_custom_command(TARGET ${app_name} POST_BUILD
        COMMAND ${ARM_OBJCOPY_EXECUTABLE} -O binary 
                $<TARGET_FILE:${app_name}> 
                $<TARGET_FILE_DIR:${app_name}>/$<TARGET_FILE_BASE_NAME:${app_name}>.bin
        COMMENT "Generating binary image: ${app_name}.bin"
    )
endfunction()
